package cn.signalpha.modules.shop.service;

import cn.signalpha.core.tool.utils.BeanUtil;
import cn.signalpha.core.tool.utils.ObjectUtil;
import cn.signalpha.modules.shop.entity.SellerVerify;
import cn.signalpha.modules.shop.excel.SellerVerifyExcel;
import cn.signalpha.modules.shop.mapper.SellerVerifyMapper;
import cn.signalpha.modules.shop.vo.SellerVerifyVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 服务类
 *
 * @author signalpha
 */
@Service
public class SellerVerifyService extends ServiceImpl<SellerVerifyMapper, SellerVerify> {

	/**
	 * 自定义分页
	 */
    public IPage<SellerVerifyVO> selectSellerVerifyPage(IPage<SellerVerifyVO> page, Map<String, Object> params) {
        return page.setRecords(baseMapper.selectSellerVerifyPage(page, params));
    }

	/**
	 * 自定义列表
	 */
	public List<SellerVerifyVO> selectSellerVerifyList(Map<String, Object> params) {
		return baseMapper.selectSellerVerifyPage(null, params);
	}

    /**
	 * 自定义导出
	 */
    public List<SellerVerifyExcel> selectSellerVerifyExcel(Map<String, Object> params) {
        return BeanUtil.copy(baseMapper.selectSellerVerifyPage(null, params), SellerVerifyExcel.class);
    }

    /**
	 * 自定义Wrappers
	 */
    public QueryWrapper<SellerVerify> selectSellerVerifyWrapper(Map<String, Object> params) {
        QueryWrapper<SellerVerify> wrapper = Wrappers.query();
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("sellerId")), SellerVerify::getSellerId, params.get("sellerId"));
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("userId")), SellerVerify::getUserId, params.get("userId"));
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("createTime")), SellerVerify::getCreateTime, params.get("createTime"));
        wrapper.lambda().orderByDesc(SellerVerify::getId);
        return wrapper;
    }

	/**
	 * 统计
	 */
	public long countBySellerIdAndUserId(Long sellerId, Long userId) {
		return baseMapper.selectCount(Wrappers.<SellerVerify>lambdaQuery().eq(SellerVerify::getSellerId, sellerId).eq(SellerVerify::getUserId, userId));
	}
}

